#LOCALE_HEBREW=he_IL yi_US
#LOCALE_INDIAN=ar_IN bn_IN en_IN hi_IN kn_IN gu_IN mr_IN ml_IN pa_IN ta_IN te_IN bn_BD 
#LOCALE_ARABIC=ar_AE ar_BH ar_DZ ar_EG ar_IN ar_IQ ar_JO ar_KW ar_LB ar_LY ar_MA ar_OM ar_QA ar_SA ar_SD ar_SY ar_TN ar_YE
#LOCALE_CJK=ko_KR ja_JP zh_CN zh_HK zh_SG zh_TW
#LOCALE_ALL=$(LOCALE_HEBREW) $(LOCALE_INDIAN) $(LOCALE_ARABIC) $(LOCALE_CJK)

LOCALE_ALL=zh_CN zh_HK ko_KR ca_ES be_BY pa_IN cy_GB
TRANSLATION_ALL=zh_CN zh_HK zh_TW ko bg hu el km ca be_BY pa cy fa

all: locale-all

locale-all: build
		
build: build-stamp
	
build-stamp:
	mkdir -p $(CURDIR)/build
	@for i in $(LOCALE_ALL); do \
		echo "Building locale $$i (UTF-8)"; \
		I18NPATH=$(CURDIR)/locales/ localedef -c --quiet \
			 --charmap=$(CURDIR)/charmaps/UTF-8 --inputfile=$$i build/$$i; \
	done

	@for i in $(TRANSLATION_ALL); do \
		echo "Building translation $$i"; \
		(cd po/$$i/LC_MESSAGES && make build); \
	done

	@touch build-stamp

install: build
	@for i in $(LOCALE_ALL); do \
		echo "Installing locale $$i"; \
		mkdir -p $(DESTDIR)/usr/lib/locale/$$i; \
		cp -r $(CURDIR)/build/$$i $(DESTDIR)/usr/lib/locale; \
	done

	@for i in $(TRANSLATION_ALL); do \
		echo "Installing translation $$i"; \
		mkdir -p $(DESTDIR)/usr/share/locale/$$i/LC_MESSAGES; \
		cp $(CURDIR)/po/$$i/LC_MESSAGES/*.mo \
		   $(DESTDIR)/usr/share/locale/$$i/LC_MESSAGES;\
	done

clean:
	rm -f build-stamp
	rm -rf $(CURDIR)/build
	rm -f $(CURDIR)/po/*/LC_MESSAGES/*.mo
